package com.dp.mallchat.common.common.thread;

import lombok.AllArgsConstructor;
import org.jetbrains.annotations.NotNull;

import java.util.concurrent.ThreadFactory;

/**
 * @Author: dupeng
 * @CreateTime: 2024-05-29  14:55
 * @Description: TODO
 */
@AllArgsConstructor
public class MyThreadFactory implements ThreadFactory {

    public static final MyUncaughtExceptionHandler MY_UNCAUGHT_EXCEPTION_HANDLER = new MyUncaughtExceptionHandler();
    private final ThreadFactory threadFactory;


    @Override
    public Thread newThread(@NotNull Runnable r) {
        Thread thread = threadFactory.newThread(r);
        // 线程池 线程错误日志记录
        thread.setUncaughtExceptionHandler(MY_UNCAUGHT_EXCEPTION_HANDLER);
        return thread;
    }
}
